import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

// 防止路由重复点击报错
const originalPush = VueRouter.prototype.push

VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes = [
  {
    path: '/',
    redirect: {
      name: 'home'
    }
  },
  {
    path: '/home',
    name: 'home',
    component: () => import('@/views/Home.vue'),
    redirect: 'index',
    children: [{
      path: '/index',
      name: 'index',
      component: () => import('@/views/Index/Index.vue')
    }, {
      path: 'user',
      name: 'user',
      component: () => import('@/views/User/User')
    }, {
      path: 'type',
      name: 'type',
      component: () => import('@/views/Type/Type')
    }, {
      path: 'sku',
      name: 'sku',
      component: () => import('@/views/Sku/Sku')
    }, {
      path: 'key',
      name: 'key',
      component: () => import('@/views/Sku/Key/Key')
    }, {
      path: 'value',
      name: 'value',
      component: () => import('@/views/Sku/Value/Value')
    }]
  }, {
    path: '/login',
    name: 'login',
    component: () => import('@/views/Login.vue')
  },
  {
    path: '/about',
    name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  }
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})


export default router
